﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Bass.Tools;
using MySql.Data.MySqlClient;

public partial class admin_admin_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["adminname"]) == "")
        {
            Response.Write("<script language=javascript>alert('您没有登录');window.parent.document.location.href ='admin_login.aspx'</script>");
        }
        else if (!IsPostBack)
        {
            
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (IsValid == true)
        {
            //OleDbConnection Conn = new OleDbConnection();
            //Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("../miumiu.mdb");
            //Conn.Open();

            //取到连接字符串
            string propertiesPath = Server.MapPath("../mysqldb.properties");
            mytools mt = new mytools();
            string ConnString = mt.getMysqlConn(propertiesPath);

            //打开连接
            MySqlConnection myConnection = new MySqlConnection(ConnString);
            myConnection.Open();

            string pwd = this.adminpwd.Text.ToString();
            string pwd_md5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5");
            MySqlCommand Comm = new MySqlCommand("update admin_info set adminpwd='" + pwd_md5 + "' where adminname='" + Session["adminname"] + "'", myConnection);
            Comm.ExecuteNonQuery();
            myConnection.Close();
            Response.Write("<script language=javascript>alert('修改成功');location='admin_edit.aspx'</script>");
        }
    }

   
    protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
    {
        //OleDbConnection Conn = new OleDbConnection();
        //Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("../miumiu.mdb");
        //Conn.Open();

        //取到连接字符串
        string propertiesPath = Server.MapPath("../mysqldb.properties");
        mytools mt = new mytools();
        string ConnString = mt.getMysqlConn(propertiesPath);

        //打开连接
        MySqlConnection myConnection = new MySqlConnection(ConnString);
        myConnection.Open();

        string oldpwd = this.adminoldpwd.Text.ToString();
        string oldpwd_md5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(oldpwd, "md5");
        MySqlCommand cmd = new MySqlCommand("select count(*) from admin_info where adminname='" + Session["adminname"] + "' and adminpwd='" + oldpwd_md5 + "'", myConnection);
        int count = Convert.ToInt32(cmd.ExecuteScalar());
        if (count > 0)
        {
            args.IsValid = true;
        }
        else
        {
            args.IsValid = false;
        }
        myConnection.Close();
    }

}

